import time
from naoqi import ALProxy
import threading

def runBehaviors(managerProxy):
    names = managerProxy.startBehavior('guojia/behavior_1')
    print "runing!"
    print managerProxy.getRunningBehaviors()

ip1 = '192.168.1.107'
ip2 = '192.168.1.102'
ip3 = '192.168.1.100'
ip4 = '192.168.1.104'
'''
ip5 = '192.168.1.105'
ip6 = '192.168.1.101'
'''
#ip7 = '192.168.1.103'
#ip8 = '192.168.1.107'

managerProxy1 = ALProxy("ALBehaviorManager", ip1, 9559)
managerProxy2 = ALProxy("ALBehaviorManager", ip2, 9559)
managerProxy3 = ALProxy("ALBehaviorManager", ip3, 9559)
managerProxy4 = ALProxy("ALBehaviorManager", ip4, 9559)
'''
managerProxy5 = ALProxy("ALBehaviorManager", ip5, 9559)
managerProxy6 = ALProxy("ALBehaviorManager", ip6, 9559)
'''
#managerProxy7 = ALProxy("ALBehaviorManager", ip7, 9559)
#managerProxy8 = ALProxy("ALBehaviorManager", ip8, 9559)
managerProxy1.preloadBehavior("guojia/behavior_1")
managerProxy2.preloadBehavior("guojia/behavior_1")
managerProxy3.preloadBehavior("guojia/behavior_1")
managerProxy4.preloadBehavior("guojia/behavior_1")
'''
managerProxy5.preloadBehavior("guojia/behavior_1")
managerProxy6.preloadBehavior("guojia/behavior_1")
'''
#managerProxy7.preloadBehavior("little-apple-dance")
#managerProxy8.preloadBehavior("little-apple-dance")
time.sleep(5)
threads = []
t1 = threading.Thread(target = runBehaviors, args = (managerProxy1,))
threads.append(t1)
t2 = threading.Thread(target = runBehaviors, args = (managerProxy2,))
threads.append(t2)
t3 = threading.Thread(target = runBehaviors, args = (managerProxy3,))
threads.append(t3)
t4 = threading.Thread(target = runBehaviors, args = (managerProxy4,))
threads.append(t4)
'''
t5 = threading.Thread(target = runBehaviors, args = (managerProxy5,))
threads.append(t5)
t6 = threading.Thread(target = runBehaviors, args = (managerProxy6,))
threads.append(t6)
'''
#t7 = threading.Thread(target = runBehaviors, args = (managerProxy7,))
#threads.append(t7)
#t8 = threading.Thread(target = runBehaviors, args = (managerProxy8,))
#threads.append(t8)

if __name__ == '__main__':
    for t in threads:
        t.start()
    time.sleep(180.0)
    if managerProxy2.isBehaviorRunning('guojia/behavior_1'):
        managerProxy2.stopBehavior('guojia/behavior_1')
        time.sleep(1.0)
    else:
        print "Behavior is already stopped."
